import csv
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np


plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['axes.unicode_minus'] = False

with open('F:/肥西2017-2022年房价.csv', 'r', encoding='utf-8') as f:
    f_csv = csv.reader(f)
    headers = next(f_csv)

    # for row in f_csv:
    #     print(row)


readData = pd.read_csv("F:/肥西2017-2022年房价.csv", skiprows=0)  # 读取csv数据
#打印
print(readData)
#[64 rows x 3 columns]
xdata = []
ydata = []
xdata = readData.loc[:, '年份']
ydata = readData.loc[:, '均价']
data = readData.iloc[:, 2].tolist()  # 获取dataFrame中的第3列，并将此转换为list
#Data = readData.iloc[0, 1].tolist()
xData = list(range(1, len(data)+1))  # 产生横轴坐标
print('--------------------------------')
print(data)

#画的是年表
plt.plot(xdata, ydata, 'bo-', label=u'', linewidth=1)
plt.title(u"肥西2017-2022年房价", size=10)  # 设置表名为“表名”
plt.legend()
plt.xlabel(u'x轴名：年份', size=20)  # 设置x轴名为“x轴名”
plt.ylabel(u'y轴名：均价', size=10)  # 设置y轴名为“y轴名”
plt.show()

#还应有个月表
